package com.huilian.iotbox.admin.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * MQConfig
 * 延迟队列配置器
 *
 * @Author mineChen
 * @Date 2021/3/23 21:15
 */
@Configuration
public class DelayMQConfig {

    /**
     * 延迟消息交换机
     */
    public static final String IOT_BOX_ADMIN_LAZY_EXCHANGE = "iotBox.admin_lazy_exchange";
    /**
     * 延迟队列
     */
    public static final String IOT_BOX_ADMIN_LAZY_QUEUE = "iotBox_admin_lazy_queue";
    /**
     * 延迟队列路由key
     */
    public static final String BOX_ADMIN_LAZY_QUEUE_KEY = "iotBox.admin_lazy_queue";

    /**
     * 延迟消息交换机
     */
    public static final String IOT_BOX_CLIENT_LAZY_EXCHANGE = "iotBox.client_lazy_exchange";
    /**
     * 延迟队列路由key
     */
    public static final String BOX_CLIENT_LAZY_QUEUE_KEY = "iotBox.client_lazy_queue";


    // 延迟队列路由key-劵码核销key
    public static final String IOT_BOX_CLIENT_VERIFY_UP_COIN_KEY = "iot-box-client-verify-up-coin";



    // 延迟队列-iotBox_client_lazy_queue
    public static final String IOT_BOX_ADMIN_BEABOUTTOEXPIRE_TICKETRECORD_LAZY_QUEUE = "iotBox_admin_beAboutToExpire_ticketRecord_lazy_queue";
    // 延迟队列路由key
    public static final String BOX_ADMIN_BEABOUTTOEXPIRE_TICKETRECORD_LAZY_QUEUE_KEY = "iotBox.admin_beAboutToExpire_ticketRecord_lazy_key";


    /**wap端延迟队列消费配置-begin*/
    /**
     * 延迟消息交换机
     */
    public static final String IOT_BOX_WAP_LAZY_EXCHANGE = "iotBox.wap_lazy_exchange";
    /**
     * 活动未开始————>开始，延迟队列路由key
     */
    public static final String IOT_BOX_WAP_ACTIVITY_START_STATE_LAZY_QUEUE_KEY = "iotBox_wap_activity_start_state_lazy_queue_key";
    /**
     * 活动进行中————>结束，延迟队列路由key
     */
    public static final String IOT_BOX_WAP_ACTIVITY_END_STATE_LAZY_QUEUE_KEY = "iotBox_wap_activity_end_state_lazy_queue_key";
    /**wap端延迟队列消费配置-end*/

    @Bean
    public TopicExchange iotBoxAdminLazyExchange() {
        Map<String, Object> pros = new HashMap<>();
        //设置交换机支持延迟消息推送
        pros.put("x-delayed-message", "topic");
        TopicExchange exchange = new TopicExchange(IOT_BOX_ADMIN_LAZY_EXCHANGE, true, false, pros);
        exchange.setDelayed(true);
        return exchange;
    }

    @Bean
    public Queue iotBoxAdminLazyQueue() {
        return new Queue(IOT_BOX_ADMIN_LAZY_QUEUE, true);
    }

    @Bean
    public Binding iotBoxAdminLazyBinding() {
        return BindingBuilder.bind(iotBoxAdminLazyQueue()).to(iotBoxAdminLazyExchange()).with(BOX_ADMIN_LAZY_QUEUE_KEY);
    }


    @Bean
    public Queue iotBoxBeAboutToExpireTicketRecordLazyQueue() {
        return new Queue(IOT_BOX_ADMIN_BEABOUTTOEXPIRE_TICKETRECORD_LAZY_QUEUE, true);
    }
    @Bean
    public Binding iotBeAboutToExpireTicketRecordLazyBinding() {
        return BindingBuilder.bind(iotBoxBeAboutToExpireTicketRecordLazyQueue()).to(iotBoxAdminLazyExchange()).with(BOX_ADMIN_BEABOUTTOEXPIRE_TICKETRECORD_LAZY_QUEUE_KEY);
    }

}
